/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */
package com.jf.cloud.unicomdata.controller.admin;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.unicomdata.dto.HourDataDTO;
import com.jf.cloud.unicomdata.model.HourData;
import com.jf.cloud.unicomdata.service.HourDataService;
import com.jf.cloud.unicomdata.service.ScenicSpotService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import ma.glasnost.orika.MapperFacade;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * 联通小时数据
 *
 * @author zz
 * @date 2023-04-24 17:46:00
 */
@RestController("unicomHourDataController")
@RequestMapping("/unicom/hour_data")
@Tag(name = "联通小时数据")
public class HourDataController {

    @Autowired
    private HourDataService hourDataService;

    @Autowired
    private ScenicSpotService scenicSpotService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取联通小时数据列表", description = "分页获取联通小时数据列表")
    public ServerResponseEntity<PageVO<HourData>> page(@Valid PageDTO pageDTO, @ParameterObject HourDataDTO hourDataDTO) {
        PageVO<HourData> hourDataPage = hourDataService.page(pageDTO, hourDataDTO);
        return ServerResponseEntity.success(hourDataPage);
    }

    @GetMapping("/matou")
    @Operation(summary = "获取联通小时数据列表", description = "分页获取联通小时数据列表")
    public ServerResponseEntity<Map> matou() {
        return ServerResponseEntity.success(scenicSpotService.getDataByMaTou());
    }

    @GetMapping
    @Operation(summary = "获取联通小时数据", description = "根据dataId获取联通小时数据")
    public ServerResponseEntity<HourData> getByDataId(@RequestParam Long dataId) {
        return ServerResponseEntity.success(hourDataService.getByDataId(dataId));
    }

    @PostMapping
    @Operation(summary = "保存联通小时数据", description = "保存联通小时数据")
    public ServerResponseEntity<Void> save(@Valid @RequestBody HourDataDTO hourDataDTO) {
        HourData hourData = mapperFacade.map(hourDataDTO, HourData.class);
        hourData.setDataId(null);
        hourDataService.save(hourData);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新联通小时数据", description = "更新联通小时数据")
    public ServerResponseEntity<Void> update(@Valid @RequestBody HourDataDTO hourDataDTO) {
        HourData hourData = mapperFacade.map(hourDataDTO, HourData.class);
        hourDataService.update(hourData);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除联通小时数据", description = "根据联通小时数据id删除联通小时数据")
    public ServerResponseEntity<Void> delete(@RequestParam Long dataId) {
        hourDataService.deleteById(dataId);
        return ServerResponseEntity.success();
    }
}
